<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //自定义迭代器
        let banji = {
            name: '1b',
            members: [
                'zs',
                'ls',
                'ww',
            ],
            [Symbol.iterator]() {
                let index = 0
                let that = this
                //迭代器必须返回一个含有next()方法的对象，next()方法必须返回{value: any, done: bool}对象
                return {
                    next: function() {
                        if (index < that.members.length) {
                            return {
                                value:that.name + '-' + that.members[index++],
                                done: index > that.members.length
                            }
                        } else{
                            return { value: null, done: true}
                        }
                    }
                }
            }
        }
        //要求for of遍历结果为：1b-zs 1b-ls 1b-ww
        for(let v of banji) {
            console.log(v)
        }
    </script>
</body>
</html>